package com.bwf.daemon;

import java.io.IOException;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/19 15:09
 * @Copyright 博为峰
 */
public class DeamonDemo extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + ":i=" + i);
        }
    }
    //将该线程标记为守护线程或用户线程。当正在运行的线程都是守护线程时，Java 虚拟机退出。
    public static void main(String[] args) throws IOException {
        final DeamonDemo deamonDemo = new DeamonDemo();
        deamonDemo.setDaemon(true);//守护线程
        deamonDemo.start();

        System.in.read();
    }
}
